 package com.comtime.smartbox;

 import android.content.Intent;
 import android.os.Bundle;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.widget.CompoundButton;
 import android.widget.CompoundButton.OnCheckedChangeListener;
 import android.widget.ToggleButton;

 import com.comtime.mybox.AboutActivity;
 import com.comtime.mybox.AntiLostAlarmManagerActivity;
 import com.comtime.mybox.BatteryManagerActivity;
 import com.comtime.mybox.FeedBackActivity;
 import com.comtime.mybox.FingerprintManagerActivity;
 import com.comtime.service.MyService;
 import com.comtime.smartkilimanjaro.R;
 import com.comtime.utils.MyConfig;
 import com.comtime.utils.MySharedPreferences;
 import com.comtime.view.MyDialog;

public class Activity_3 extends BaseActivity {

	MySharedPreferences mySharedPreferences;
	HBApplication application;
	ToggleButton tb_distub;

	float density = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_3);
		mySharedPreferences = MySharedPreferences.getInstance(this);
		application = (HBApplication) getApplication();
		density = getResources().getDisplayMetrics().density;
		init();

	}

	/**
	 * guan lian
	 */
	void init() {
		tb_distub = (ToggleButton) findViewById(R.id.tb_not_disturb);
		tb_distub.setChecked(mySharedPreferences.getDisturbWainAction());
		tb_distub.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton arg0, boolean b) {
				mySharedPreferences.saveDisturbWainAction(b);
				if(application.swDevicesList.get(0).isConnected()){
					if(b){
						application.swDevicesList.get(0).stopAntilost();
					}else{
						application.swDevicesList.get(0).startAntilost();

					}
				}
			}
		});
		//默认开启免打扰
		tb_distub.setChecked(true);
	}

	public void AddBoxAction(View v) {
		if (!MyConfig.canUse) {
			showCanUseDialog(getText(R.string.unsupport_ble).toString());
			return;
		}
		int select_tag = 0;
		for (int i = 0; i < 3; i++) {
			if (application.swDevicesList.get(i).getBluetoothDevice() == null) {
				select_tag = i;
				break;
			}
		}
		Intent intent = new Intent(MyService.ACTION_UPDATE_UI);
		intent.putExtra(MyService.SELECT_TAG, select_tag);
		sendBroadcast(intent);
	}

	public void BatteryManeger(View v) {
		Intent intent = new Intent(this, BatteryManagerActivity.class);
		startActivity(intent);
	}

	public void LostWainAction(View v) {
		Intent intent = new Intent(this, AntiLostAlarmManagerActivity.class);
		startActivity(intent);
	}


	/*public void OpenBoxAction(View v) {
		Intent intent = new Intent(this, FingerprintManagerActivity.class);
		startActivity(intent);
	}*/

	public void HelpFeedAction(View v) {
		Intent intent = new Intent(this, FeedBackActivity.class);
		startActivity(intent);
	}

	public void AboutWeAction(View v) {
		Intent intent = new Intent(this, AboutActivity.class);
		startActivity(intent);
	}

	protected void onResume() {
		super.onResume();

	};

	/**
	 * 不支持4.3以下
	 * 
	 * @param str
	 */
	void showCanUseDialog(String str) {
		final MyDialog myDialog = new MyDialog(Activity_3.this);
		myDialog.setContent(str);
		myDialog.getLeftButton().setText(getText(R.string.ok));
		myDialog.getLeftButton().setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				myDialog.dismiss();

			}
		});

		myDialog.show();
	}

}
